package com.bjsxt.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bjsxt.pojo.Applicationlog;
import com.bjsxt.pojo.Drug;
import com.bjsxt.pojo.Provider;
import com.bjsxt.service.WarehouseService;
/**
 * 
 * @author qxx
 *
 */
@Controller
@RequestMapping("/Warehouse")
public class WarehouseController {
	@Autowired
	private WarehouseService ws;
	
	/**
	 * 查询所有药品信息
	 * @param page 第几页，默认第一页
	 * @param rows 一页多少条数据
	 * @return 返回一个对应当页条数和信息的list供应商集合
	 * @return List<Drug> 返回药品库存信息集合
	 */
	@RequestMapping("/findAllInfo")
	@ResponseBody
	public List<Drug> fingWarehouseInfo(){
		return ws.findWarehouseInfo();
	}
	/**
	 * 
	 * @param al 封装申请信息
	 * @return 返回map状态值
	 */
	@RequestMapping("/application")
	@ResponseBody
	public Map<String, Integer> addApplication(Applicationlog al){
		al.setIsagree(0);
		Map<String, Integer>map=new HashMap<>();
		try{
			ws.addApplication(al);
			map.put("state", 200);
			return map;
		}catch(Exception e){
			e.printStackTrace();
			map.put("state", 500);
			return map;
		}
	}
	/**
	 * 获取所有未审核的请求信息
	 * @return Applicationlog对象的集合
	 */
	@RequestMapping("/findApplication")
	@ResponseBody
	public List<Applicationlog> findApplicationInfo(){
		
		return ws.findApplication();
	}
	/**
	 * 获取所有请求信息
	 * @return Applicationlog对象的集合
	 */
	@RequestMapping("/findAllApplication")
	@ResponseBody
	public List<Applicationlog> findAllApplicationInfo(){
		
		return ws.findAllApplication();
	}
	
	/**
	 * 获取所有供应商信息
	 */
	@RequestMapping("/provider")
	@ResponseBody
	public List<Provider> findProviderInfo(){
		
		return ws.findProInfo();
	}
	
	@RequestMapping("/outPut")
	@ResponseBody
	public Map<String,Integer> outPutDrugInfo(){
		ws.outPutInfo();
		Map<String,Integer>map=new HashMap<>();
		try {
			map.put("state", 200);
			return map;
		} catch (Exception e) {
			map.put("state", 500);
			return map;
		}
	}
	
	@RequestMapping("/agreeApplication")
	@ResponseBody
	public Map<String,Integer> modifyApplication(Integer logid,Integer applicationnum,String drugname){
		ws.updateAgree(logid,applicationnum, drugname);
		Map<String,Integer>map=new HashMap<>();
		try {
			map.put("state", 200);
			return map;
		} catch (Exception e) {
			e.printStackTrace();
			map.put("state", 500);
			return map;
		}
	}
	
	@RequestMapping("/disagreeApplication")
	@ResponseBody
	public Map<String,Integer> dropApplication(Integer logid){
		ws.dropApplication(logid);
		Map<String,Integer>map=new HashMap<>();
		try {
			map.put("state", 200);
			return map;
		} catch (Exception e) {
			e.printStackTrace();
			map.put("state", 500);
			return map;
		}
	}
	@RequestMapping("/findAgreeApplication")
	@ResponseBody
	public List<Applicationlog> findAgreeApplication(){
		List<Applicationlog> list=ws.findAgree();
		return list;
	}
}
